package com.sq.system.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sq.common.web.domain.AjaxResult;
import com.sq.system.mapper.SysPileDao;
import com.sq.system.pojo.SysPile;
import com.sq.system.service.SysPileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * (SysPile)表服务实现类
 *
 * @author makejava
 * @since 2025-02-25 10:18:47
 */
@Service("sysPileService")
public class SysPileServiceImpl extends ServiceImpl<SysPileDao, SysPile> implements SysPileService {

    @Override
    public List<SysPile> readExcelFile(MultipartFile file) {
        List<SysPile> sysPileList = new ArrayList<>();
        try {
            EasyExcel.read(file.getInputStream(), SysPile.class, new AnalysisEventListener<SysPile>() {
                @Override
                public void invoke(SysPile sysPile, AnalysisContext analysisContext) {
                    sysPileList.add(sysPile);
                }

                @Override
                public void doAfterAllAnalysed(AnalysisContext analysisContext) {
                    // 所有数据解析完成后的操作，可以在这里处理 userList
                }
            }).sheet().doRead();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return sysPileList;
    }
}

